import 'package:flutter/material.dart';
import 'package:flutter_provider_demo/shopping/model/shopping_provider.dart';
import 'package:flutter_provider_demo/shopping/shopping_page.dart';
import 'package:provider/provider.dart';

import 'shoping_cart/model/shopping_cart_provider.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MultiProvider(
      providers: [
        //商品数据
        Provider(create: (_) => ShoppingProvider()),
        ChangeNotifierProxyProvider<ShoppingProvider, ShoppingCartProvider>(
          create: (_) => ShoppingCartProvider(),
          update: (_, shoppingProvider, shoppingCartProvider) {
            shoppingCartProvider.shoppingProvider = shoppingProvider;
            return shoppingCartProvider;
          },
        )
      ],
      child: MaterialApp(
        title: 'Flutter Provider Demo',
        theme: ThemeData(
          primarySwatch: Colors.blue,
          visualDensity: VisualDensity.adaptivePlatformDensity,
        ),
        home: ShoppingPage(),
      ),
    );
  }
}
